/* Creado el  18/04/2006 */
package com.angel.architecture.persistence.base;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.Type;

import com.angel.architecture.persistence.ids.ObjectId;
import com.angel.common.helpers.ObjectIdHelper;

/**
 *  Esta deberia ser la clase base para todos los objetos de negocio que no requieran ser persistidos
 *
 * @author ALeinvand
 * @version $Revision: 1.5.4.10 $
 */
@MappedSuperclass
public abstract class BusinessObject implements Serializable{

	private static final long serialVersionUID = -1281322143495754442L;

	@Id
    @Column(name="ID",length=36)
    @Type(type="com.angel.architecture.hibernate3.converters.ObjectIdConverter")
    private ObjectId objectId = ObjectIdHelper.createObjectId();


    protected BusinessObject() {
        super();
    }

    @SuppressWarnings("unchecked")
	public int compareTo(Object otherObject) {
        BusinessObject otherBusinessObject = ( BusinessObject ) otherObject;
        return this.getId().compareTo(otherBusinessObject.getId());
    }

    public boolean equals(Object o) {
        if ( this == o ) {
            return true;
        }
        if ( !(o instanceof BusinessObject) ) {
            return false;
        }

        final BusinessObject businessObject = ( BusinessObject ) o;

        if ( this.getId() != null ? !this.getId().equals(businessObject.getId()) : businessObject.getId() != null ) {
            return false;
        }

        return true;
    }

    public int hashCode() {
        return (this.getId() != null ? this.getId().hashCode() : 0);
    }

    public ObjectId getId() {
        return objectId;
    }
    public void setId(ObjectId objectId) {
        this.objectId = objectId;
    }

    /**
     * Devuelve el ObjectId representado como String.
     * util para no tener que andar agregando esta logica por todos lados.
     * @return String con la representacion del ObjectId
     * @author IFritzler
     * @version 1.0
     */
    public String getIdAsString(){
    	return this.getId().getIdAsString();
    }

}
